package com.tencent.qcloud.tim.uikit.utils;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 创建者 zx
 * 创建时间 2021/2/26 11:16
 */
public class AI {
    private final String TAG = "AIUitl";

    private Map<String, String> problemAndAnswer; //问题和答案
    private List<String> problems;//问题
    private List<String> answers;//答案

    public AI(Map<String, String> problemAndAnswer) {
        this.problemAndAnswer = problemAndAnswer;
        init();
    }

    private void init() {
        problems = new ArrayList<>();
        answers = new ArrayList<>();
        if (problemAndAnswer == null) return;
        for (String problem : problemAndAnswer.keySet()) {
            problems.add(problem);
            answers.add(problemAndAnswer.get(problem));
        }
    }

    /**
     * 输入问题，得到答案。
     *
     * @param problem
     * @return answer
     */
    public String problem(String problem) {
        String answer = null;
        try {
            answer = problemAndAnswer.get(problem);
            if (TextUtils.isEmpty(answer)) {
                int index = Integer.parseInt(problem) - 1;
                answer = problemAndAnswer.get(problems.get(index));
            }
        } catch (Exception e) {
            return "不太明白您在说什么，更多问题请转人工哦~~";
        }
        return answer;
    }


}
